package com.yuan.springcloud.order.feign;

import com.yuan.springcloud.order.entity.Product;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Feign微服务调用
 *
 * @author YouYuan
 * @version 1.0
 * @date 2020/3/28 2:22
 */
@FeignClient(name = "service-product", fallback = ProductFeignClientFallback.class)
@Component //不加这个注解也可以，但是IDEA检测自动注入会提示找不到Bean
public interface ProductFeignClient {

    /**
     * 配置需要调用的微服务接口
     */
    @RequestMapping(value = "/product/{id}", method = RequestMethod.GET)
    Product findById(@PathVariable Long id);

    /**
     * Feign远程调用的参数需要使用@RequestParam、@RequestBody声明传递
     */
    @RequestMapping(value = "/product/msg", method = RequestMethod.GET)
    String msg(@RequestParam("msg") String msg);
}
